package com.wenwei.sharebox.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wenwei.sharebox.R;
import com.wenwei.sharebox.bean.UserShareBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/7.
 */
public class UserShareAdapter extends RecyclerView.Adapter<UserShareAdapter.MyViewHolder> {
    private CallBack mCallBack;
    private Context mContext;
    public interface CallBack {
        void onItemClick(UserShareBean.DataBean bean);

        void onReturnMoney();
    }

    private List<UserShareBean.DataBean> mList;

    public void setShareDataList(List<UserShareBean.DataBean> list) {
        this.mList = list;
    }

    public UserShareAdapter(CallBack callBack) {
        this.mCallBack = callBack;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_user_share, null));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.onItemClick(mList.get(position));
            }
        });
//        holder.returnMoney.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mCallBack.onReturnMoney();
//            }
//        });
        holder.itemName.setText(mList.get(position).getShopName());
        Glide.with(mContext).load(mList.get(position).getShopImg()).into(holder.itemShareImg);
        holder.itemPrice.setText("￥"+mList.get(position).getPayTotal());
        holder.addressTv.setText(mList.get(position).getAddressName());
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.item_share_img)
        ImageView itemShareImg;
        @Bind(R.id.item_name)
        TextView itemName;
        @Bind(R.id.item_price)
        TextView itemPrice;
        @Bind(R.id.return_money)
        TextView returnMoney;
        @Bind(R.id.item_location)
        TextView addressTv;
        public MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }


}
